package goodash

func Incr[K comparable](m map[K]int, k K, delta int) map[K]int {
	if m == nil {
		m = make(map[K]int)
	}
	if _, ok := m[k]; ok {
		m[k] += delta
	} else {
		m[k] = delta
	}
	return m
}

func Max[K comparable](m map[K]int, k K, newValue int) map[K]int {
	if m == nil {
		m = make(map[K]int)
	}
	if v, ok := m[k]; !ok || v < newValue {
		m[k] = newValue
	}
	return m
}

func Min[K comparable](m map[K]int, k K, newValue int) map[K]int {
	if m == nil {
		m = make(map[K]int)
	}
	if v, ok := m[k]; !ok || v > newValue {
		m[k] = newValue
	}
	return m
}
